package util;

import java.util.ArrayList;
import java.util.List;

import com.gxuwz.Market.business.entity.ServiceField;
import com.gxuwz.Market.business.entity.ServiceForm;

public class FieldUtil {
	/**
	 * 将表格信息解析成字段类型数组
	 * @param serviceForm
	 * @return
	 */
	public static List<ServiceField> fieldOfForm(ServiceForm serviceForm){
		List<ServiceField> list = new ArrayList<ServiceField>();
		String[] fieldNames = serviceForm.getFieldNames().split(",");
		String[] fieldLen = serviceForm.getFieldLen().split(",");
		String[] fieldType = serviceForm.getFieldType().split(",");
		
		int n = serviceForm.getFieldNum();
		
		for(int i=0;i<n;i++){
			ServiceField serviceField = new ServiceField();
			serviceField.setName(fieldNames[i]);
			serviceField.setLen(fieldLen[i]);
			serviceField.setType(fieldType[i]);
			serviceField.setValue("data"+i);
			list.add(serviceField);
		}
		
		return list;
	}
	
	/**
	 * 将表格信息解析成字段类型数组(不赋值value)
	 * @param serviceForm
	 * @return
	 */
	public static List<ServiceField> fieldOfFormNo(ServiceForm serviceForm){
		List<ServiceField> list = new ArrayList<ServiceField>();
		String[] fieldNames = serviceForm.getFieldNames().split(",");
		String[] fieldLen = serviceForm.getFieldLen().split(",");
		String[] fieldType = serviceForm.getFieldType().split(",");
		
		int n = serviceForm.getFieldNum();
		
		for(int i=0;i<n;i++){
			ServiceField serviceField = new ServiceField();
			serviceField.setName(fieldNames[i]);
			serviceField.setLen(fieldLen[i]);
			serviceField.setType(fieldType[i]);
			list.add(serviceField);
		}
		
		return list;
	}
}
